﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;

namespace WindowsGame.Input
{
	public class PhoneInputFactory : IInputFactory
	{
		private Boolean tap, hold, doubleTap;

		public PhoneInputFactory()
		{
			TouchPanel.EnabledGestures = GestureType.Tap | GestureType.DoubleTap;
		}
		
		public void Update(GameTime gameTime)
		{
			tap = hold = doubleTap = false;
			if (!TouchPanel.IsGestureAvailable)
			{
				return;
			}

			GestureSample gesture = TouchPanel.ReadGesture();
			tap = gesture.GestureType == GestureType.Tap;
			doubleTap = gesture.GestureType == GestureType.DoubleTap;
		}

		public bool Escape()
		{
			return GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed;
		}
		public bool Toggle()
		{
			return tap;
		}
		public bool Load()
		{
			return doubleTap;
		}
	}
}